#!/bin/bash

VERSION=$1

echo "Using version: ${VERSION}"

if [ "z${VERSION}" == "z" ];
then
    echo "Usage: $0 VERSION"
    exit
fi

echo "Checking for previous tag by that name"
EXISTS=`hg tags | grep ${VERSION} | wc -l`
if [ ${EXISTS} != 0 ];
then
    echo "A tag named ${VERSION} already exists, exiting"
    exit
fi

echo "Tagging mercurial as version ${VERSION}"
hg tag -m 'tagging as version ${VERSION}' ${VERSION}

echo "Cloning current repository to ../fantom-migrations-${VERSION}"
hg clone -r ${VERSION} . ../fantom-migrations-${VERSION}

echo "Archiving current directory structure to ../fantom-migrations-${VERSION}.zip"
hg archive -r ${VERSION} -t zip -p fantom-migrations-${VERSION} ../fantom-migrations-${VERSION}.zip

echo "Archiving current directory structure to ../fantom-migrations-${VERSION}.tar.gz"
hg archive -r ${VERSION} -t tgz -p fantom-migrations-${VERSION} ../fantom-migrations-${VERSION}.tar.gz

echo "Archiving current directory structure to ../fantom-migrations-${VERSION}.tar.bz2"
hg archive -r ${VERSION} -t tbz2 -p fantom-migrations-${VERSION} ../fantom-migrations-${VERSION}.tar.bz2

